<template>
  <div id="app" @click="isTimeOut()" v-if="refresh">
    <router-view />
  </div>
</template>

<script>
import { removeToken } from "./utils/auth";
export default {
  name: "App",
  provide() {
    return {
      reload: this.reload,
    };
  },
  data() {
    return {
      lastTime: null, //最后一次点击的时间
      currentTime: null,
      timeOut: 600000, //设置超时时间： 10分钟
      refresh: true, // 控制整个页面刷新
    };
  },
  created() {
    this.lastTime = new Date().getTime(); //网页第一次打开时，记录当前时间
  },
  methods: {
    isTimeOut() {
      this.currentTime = new Date().getTime();
      if (this.currentTime - this.lastTime > this.timeOut) {
        this.$store.dispatch("logout");
        this.$message.warning("登录信息已过期，请重新登录");
        setTimeout(() => {
          sessionStorage.clear();
          // localStorage.clear();
          localStorage.removeItem("routeList");
          localStorage.setItem("chang", 1);
          removeToken();
          localStorage.removeItem("user");
          removeToken();
          this.$router.replace("/login");
        });
        this.lastTime = new Date().getTime();
      } else {
        this.lastTime = new Date().getTime();
      }
    },
    reload() {
      console.log("project");
      this.refresh = false;
      this.$nextTick(() => {
        this.refresh = true;
      });
    },
  },
};
</script>


<style lang="scss">
.el-table__header tr,
.el-table__header th {
  padding: 0 !important;
  height: 45px !important;
  // line-height: 45px !important;
}
.el-button {
  font-size: 14px !important;
}
.el-table__row .el-button {
  padding: 0 !important;
}
</style>
